<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="900px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="180px">
          <el-form-item label="抽血前3个月内是否服用免疫抑制剂">
            <el-radio-group v-model="form.isImmunosuppressant">
              <el-radio :label="1">无</el-radio>
              <el-radio :label="2">有</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="免疫抑制剂选项">
            <el-select v-model="form.immunosuppressantOptions" multiple placeholder="请选择">
              <el-option
                v-for="item in immunosuppressantOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="抽血前1个月是否进行免疫治疗">
            <el-radio-group v-model="form.isImmunotherapy">
              <el-radio :label="1">无</el-radio>
              <el-radio :label="2">有</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="免疫治疗选项">
            <el-select v-model="form.immunotherapyOptions" multiple placeholder="请选择">
              <el-option
                v-for="item in immunotherapyOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="血液标本">
            <el-radio-group v-model="form.bloodSpecimen">
              <el-radio :label="1">无</el-radio>
              <el-radio :label="2">有</el-radio>
            </el-radio-group>
          </el-form-item>
          <div v-show="form.bloodSpecimen===2">
            <el-form-item label="标本采集时间">
              <el-date-picker v-model="form.specimenCollectionTime" type="datetime" style="width: 370px;" />
            </el-form-item>
            <el-form-item label="标本号">
              <el-input v-model="form.specimenNo" style="width: 370px;" />
            </el-form-item>
            <el-form-item label="是否空腹">
              <el-radio-group v-model="form.fasting">
                <el-radio :label="1">是</el-radio>
                <el-radio :label="2">否</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="标本采集类别">
              <el-select v-model="form.specimenCollectionCategory" multiple placeholder="请选择">
                <el-option
                  v-for="item in specimenCollectionCategory"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="紫头抗凝管6ml（管）">
              <el-input v-model="form.purpleAnticoagulantTube" style="width: 370px;" />
            </el-form-item>
            <el-form-item label="红头促凝管10ml（管）">
              <el-input v-model="form.redAnticoagulantTube" style="width: 370px;" />
            </el-form-item>
            <el-form-item label="标本处理时间">
              <el-date-picker v-model="form.specimenProcessingTime" type="datetime" style="width: 370px;" />
            </el-form-item>
            <el-form-item label="血清（管）">
              <el-input v-model="form.serum" style="width: 370px;" />
            </el-form-item>
            <el-form-item label="血浆（管）">
              <el-input v-model="form.plasma" style="width: 370px;" />
            </el-form-item>
            <el-form-item label="白细胞（管）">
              <el-input v-model="form.leukocyte" style="width: 370px;" />
            </el-form-item>
            <el-form-item label="淋巴细胞（管）">
              <el-input v-model="form.lymphocyte" style="width: 370px;" />
            </el-form-item>
            <el-form-item label="DNA（管）">
              <el-input v-model="form.dna" style="width: 370px;" />
            </el-form-item>
            <el-form-item label="结果">
              <el-input v-model="form.result" style="width: 370px;" />
            </el-form-item>
            <el-form-item label="样本存储时间">
              <el-date-picker v-model="form.sampleStorageTime" type="datetime" style="width: 370px;" />
            </el-form-item>
            <el-form-item label="样本种类">
              <el-checkbox-group v-model="form.sampleType" @change="show">
                <el-checkbox label="1">血清</el-checkbox>
                <el-checkbox label="2">血浆</el-checkbox>
                <el-checkbox label="3">白细胞（WBC）</el-checkbox>
                <el-checkbox label="4">淋巴细胞</el-checkbox>
                <el-checkbox label="5">DNA</el-checkbox>
              </el-checkbox-group>
              <div v-show="list.indexOf('1') !== -1"><sample :title="title1" /></div>
              <div v-show="list.indexOf('2') !== -1"><sample :title="title2" /></div>
              <div v-show="list.indexOf('3') !== -1"><sample :title="title3" /></div>
              <div v-show="list.indexOf('4') !== -1"><sample :title="title4" /></div>
              <div v-show="list.indexOf('5') !== -1"><sample :title="title5" /></div>
            </el-form-item>
          </div>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column prop="id" label="ID" />
        <el-table-column prop="pId" label="pID" />
        <el-table-column prop="isImmunosuppressant" label="抽血前3个月内是否服用免疫抑制剂" />
        <el-table-column prop="immunosuppressantOptions" label="免疫抑制剂选项" />
        <el-table-column prop="isImmunotherapy" label="抽血前1个月是否进行免疫治疗" />
        <el-table-column prop="immunotherapyOptions" label="免疫治疗选项" />
        <el-table-column prop="bloodSpecimen" label="血液标本" />
        <el-table-column v-if="checkPer(['admin','bloodSpecimen:edit','bloodSpecimen:del'])" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import sample from './sample.vue'
import crudBloodSpecimen from '@/api/bloodSpecimen'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
// import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

const defaultForm = {
  id: null,
  pId: '',
  isImmunosuppressant: null,
  immunosuppressantOptions: null,
  isImmunotherapy: null,
  immunotherapyOptions: null,
  bloodSpecimen: null,
  specimenCollectionTime: null,
  specimenNo: null,
  fasting: null,
  specimenCollectionCategory: null,
  purpleAnticoagulantTube: null,
  redAnticoagulantTube: null,
  specimenProcessingTime: null,
  serum: null,
  plasma: null,
  leukocyte: null,
  lymphocyte: null,
  dna: null,
  result: null,
  sampleStorageTime: null,
  sampleType: []
}
export default {
  name: 'BloodSpecimen',
  components: { pagination, crudOperation, udOperation, sample },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  cruds() {
    return CRUD({ title: '血液标本', url: 'api/bloodSpecimen', query: { 'pId': this.pId }, idField: 'id', sort: 'id,desc', crudMethod: { ...crudBloodSpecimen }})
  },
  data() {
    return {
      permission: {
        add: ['admin', 'bloodSpecimen:add'],
        edit: ['admin', 'bloodSpecimen:edit'],
        del: ['admin', 'bloodSpecimen:del']
      },
      rules: {
        pId: [
          { required: true, message: 'pID不能为空', trigger: 'blur' }
        ]
      },
      immunosuppressantOptions: [{
        value: '1',
        label: '硫唑嘌呤'
      }, {
        value: '2',
        label: '甲氨蝶呤'
      }, {
        value: '3',
        label: '他克莫司'
      }, {
        value: '4',
        label: '环孢素A'
      }, {
        value: '5',
        label: '利妥昔单抗'
      }, {
        value: '6',
        label: '依库珠单抗'
      }, {
        value: '7',
        label: '吗替麦考酚酯'
      }, {
        value: '8',
        label: '醋酸泼尼松'
      }, {
        value: '9',
        label: '甲泼尼龙片'
      }, {
        value: '10',
        label: '注射用甲泼尼龙琥珀酸钠'
      }],
      immunotherapyOptions: [{
        value: '1',
        label: '丙种秋蛋白'
      }, {
        value: '2',
        label: '血浆置换'
      }, {
        value: '3',
        label: '免疫吸附'
      }],
      specimenCollectionCategory: [{
        value: '1',
        label: '基线'
      }, {
        value: '2',
        label: '第一年随访'
      }, {
        value: '3',
        label: '第二年随访'
      }, {
        value: '4',
        label: '第三年随访'
      }, {
        value: '5',
        label: '第四年随访'
      }, {
        value: '6',
        label: '第五年随访'
      }, {
        value: '7',
        label: '第六年随访'
      }],
      pId: this._routerRoot._route.query.id,
      checkList: [],
      list: [],
      title1: '血清',
      title2: '血浆',
      title3: '白细胞（WBC）',
      title4: '淋巴细胞',
      title5: 'DNA'
    }
  },
  created() {
    defaultForm.pId = this.pId
    this.crud.query.pId = this.pId
  },
  methods: {
    show(v) {
      this.list = v
      console.log(this.list)
    },
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      this.crud.query.pId = this.pId
      return true
    }
  }
}
</script>

<style scoped>

</style>
